package utils

import java.io._
import java.lang.StringBuilder
import const.CConstCommons._

object CFile
{
    def write(name:String, content:String)
    {
        val wrtr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(name)))
        try {wrtr.write(content)}
        finally {wrtr.close()}
    }

    def write(name:String, content:Seq[String])
    {
        val wrtr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(name)))
        try
        {
            content foreach (s =>
            {
                wrtr.write(s)
                wrtr.newLine()
            })
        }
        finally {wrtr.close()}
    }

    def read(name:String) =
    {
        val rdr = new BufferedReader(new InputStreamReader(new FileInputStream(name)))
        try
        {
            val strBldr = new StringBuilder
            var ln = rdr.readLine()
            while(ln != null)
            {
                strBldr.append(ln)
                strBldr.append(NEW_LINE)
                ln = rdr.readLine()
            }
            strBldr.toString
        }
        finally {rdr.close()}
    }
}
